import csv
import io

# CSV数据的长字符串
csv_data = """time,cpu_percent
2024-05-28 17:54:57,14.9
2024-05-28 17:55:06,13.7"""

# 使用io.StringIO将字符串转换为文件对象
csv_file = io.StringIO(csv_data)

# 创建一个csv.reader对象
csv_reader = csv.reader(csv_file)

# 跳过表头
next(csv_reader)

# 初始化列表
time_list = []
cpu_percent_list = []

# 遍历CSV数据的每一行
for row in csv_reader:
    # 将time和cpu_percent添加到相应的列表中
    time_list.append(row[0])
    cpu_percent_list.append(float(row[1]))

# 关闭StringIO对象
csv_file.close()

# 打印结果
print("Time list:", time_list)
print("CPU Percent list:", cpu_percent_list)

""" 
Time list: ['2024-05-28 17:54:57', '2024-05-28 17:55:06']
CPU Percent list: [14.9, 13.7]

"""